package vru;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.RoundStartedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Acceptance test for Lessthan20charsyeah against Corners.
 * @author Russell Vea for ICS 314 Fall 2011.
 */
public class AcceptanceTestCorners extends RobotTestBed {
  /** The number of kills.*/
  private int kills = 0;
  /** If the robot is dead this round.*/
  private boolean dead = false;
  /** Set to true to print out amount of kills.*/
  private boolean debug = true;

  /**
   * Specifies that SittingDuck and Destroyer are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() { 
    return "sample.Corners,rvu.Lessthan20charsyeah";
  }

  /**
   * This test runs for 10 rounds.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * @param event The RoundStartedEvent.
   */
  @Override
  public void onRoundStarted(RoundStartedEvent event) { 
    this.dead = false;
  }

  /**
   * @param e Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent e) { 
    IRobotSnapshot enemy = e.getTurnSnapshot().getRobots()[0];
    if (enemy.getState().isDead() && !dead) {
      this.dead = true;
      this.kills++;
    }
  }

  /**
   * After the battle, check to see that we've visited the corners.
   *
   * @param e Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent e) {
    if (this.debug) { 
      System.out.println(this.kills);
    }
    assertTrue("Killed oppononent at least 80% of the time", this.kills >= 8);
  }
}
